import { reactive, onMounted, onBeforeUnmount } from "vue";

export default function () {
  // 定义 data
  const data = reactive({ x: 0, y: 0 });
  // 定义 methods
  const updateMouse = (e) => {
    data.x = e.pageX;
    data.y = e.pageY;
  };
  // 定义生命周期钩子函数
  onMounted(() => window.addEventListener("mousemove", updateMouse));
  onBeforeUnmount(() => window.removeEventListener("mousemove", updateMouse));
  // 将模板中要使用到的数据进行导出
  return {
    data,
  };
}
